/*
ID: icerupt1
PROG: range
LANG: C++11
*/

/* solution
 *
 * 
 *
*/
#include <fstream>
#include <iostream>
#include <algorithm>
#include <cstring>

std::ifstream fin {"range.in" };
std::ofstream fout{"range.out"};

int const maxn = 252;
char da[maxn][maxn];
int max_square[maxn][maxn];
int max_one_left[maxn][maxn];
int max_one_up[maxn][maxn];
int n;

int main()
{
	fin >> n;
	for (auto i = 1; i <= n; i++)
		for (auto j = 1; j <= n; j++) fin >> da[i][j];

	int max_len = 0;
	for (auto i = 1; i <= n; i++)
		for (auto j = 1; j <= n; j++) {
			if (da[i][j] == '0') continue;
			max_one_left[i][j] = max_one_left[i][j-1] + 1;
			max_one_up[i][j] = max_one_up[i-1][j] + 1;
			int tmp = max_square[i-1][j-1];
			max_square[i][j] = std::min(tmp + 1,
					std::min(max_one_up[i][j], max_one_left[i][j]));
			max_len = std::max(max_len, max_square[i][j]);
		}

	for (auto i = 1; i <= n; i++) {
		for (auto j = 1; j <= n; j++) std::cout << max_square[i][j] << ' ';
		std::cout << '\n';
	}

	for (auto len = 2; len <= max_len; len++) {
		int count = 0;
		for (auto i = 1; i <= n; i++)
			for (auto j = 1; j <= n; j++)
				if (max_square[i][j] >= len) count++;
		if (count) {
			std::cout << len << ' ' << count << '\n';
			fout << len << ' ' << count << '\n';
		}
	}
}

